﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Film.Repository;

namespace PhuongDoAn.UC
{
    public partial class uc_list : System.Web.UI.UserControl
    {
        int pageSize = Util.pageSize;
        int pageSegSize = 1;
        public int count = 0;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Page_PreRender(object sender, EventArgs e)
        {

            try
            {

                Page.ClientScript.GetPostBackEventReference(this, string.Empty);

                int currentPage = 1;

                string eventTarget = this.Request["__EVENTTARGET"];
                string eventArgument = this.Request["__EVENTARGUMENT"];
                if (eventTarget != String.Empty && eventTarget == "pageIndex")
                {
                    currentPage = Convert.ToInt32(eventArgument);
                }

                //Response.Write(eventArgument);
                int start = pageSize * (currentPage - 1);

                List<tblMovieTemp> result = new List<tblMovieTemp>();
                tblMovieRepository movieRepository = new tblMovieRepository();


                result = movieRepository.Filter("", "", "--Tất cả--", "--Tất cả--", start, pageSize, out count);

                rptData.DataSource = result;
                rptData.DataBind();

                if (count <= pageSize * 1)
                {
                    cbPaging.Visible = false;
                }
                else
                {
                    cbPaging.Items.Clear();
                    for (int i = 1; i <= (int)Math.Ceiling((double)count / pageSize); i++)
                    {
                        cbPaging.Items.Add(i.ToString());
                    }
                    cbPaging.SelectedValue = currentPage.ToString();
                }

            }
            catch (Exception ex)
            {
                Page.Response.Write("error");
            }
        }
    }
}